package com.JM.learningandroid;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.text.InputType;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;

public class TextPlay extends Activity implements View.OnClickListener{
	private Button btn;
	private ToggleButton tBtn;
	private EditText input;
	private TextView disp;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.text);
		init();
		tBtn.setOnClickListener(this);
		btn.setOnClickListener(this);
	}

	private void init()
	{

		btn = (Button)findViewById(R.id.button1);	
		tBtn = (ToggleButton)findViewById(R.id.toggleButton1);
		input = (EditText)findViewById(R.id.etCommands);
		disp = (TextView)findViewById(R.id.tvResults);

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch(v.getId()){
		
		case R.id.button1:
			String check = input.getText().toString().toLowerCase();
			disp.setText(check);
			if(check.contentEquals("left"))
			{
				disp.setGravity(Gravity.LEFT);
			}
			else if(check.contentEquals("right")){
				disp.setGravity(Gravity.RIGHT);
			}
			else if(check.contentEquals("center")){
				disp.setGravity(Gravity.CENTER);
			}
			else{
				int[] colorArr = {Color.BLUE,Color.RED,Color.YELLOW,Color.GREEN,Color.GRAY};
				int ind =(int)( Math.random()*colorArr.length +1)%colorArr.length;
				disp.setTextColor(colorArr[ind]);
				disp.setTextSize((float) (Math.random()*55+10));
				disp.setText("Random text equals random Size and color!");
				switch((int)(Math.random()*3))
				{
				case 0:
					disp.setGravity(Gravity.LEFT);
					break;
				case 1:
					disp.setGravity(Gravity.RIGHT);
					break;
				default:
					disp.setGravity(Gravity.CENTER);
					break;

				}
			}					
		
			break;
			
		case R.id.toggleButton1:
			
			if(tBtn.isChecked())
			{
				//tBtn.setChecked(false);
				input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
			}
			else
			{
				//tBtn.setChecked(true);
				input.setInputType(InputType.TYPE_CLASS_TEXT);
			}
			break;
		
		}
	}

}
